const express=require('express')


const fs = require('fs')
const routerXkx = express.Router()
router.post('/uplaodImageTouXiang',function(req,resp){
    let {imgUrl} = req.body
    // 1.接收到64码
    let base64Str = imgUrl.replace(/data:image\/png;base64,/,"").replace('/\s/g',"+")
    console.log(base64Str)
    // 2.将64码转成文件
    let dataBuffer = Buffer.from(base64Str,'base64')
    // 3.保存 得到保存路径
    let fileName = new Date().getTime()+"_touxiang.png"
    // fs.writeFile(保存路径,文件,保存成共后执行的函数)
    fs.writeFile(`./src/upload/${fileName}`,dataBuffer,function(err,data){
        let url = `./src/upload/${fileName}`
        /*省略了保存数据库*/
        resp.send({data:`./upload/${fileName}`})
    })
    // 4.将路径保存数据库
    // 5.返回正确信息或者错误信息
})

router.post('/sendCode',function(req,resp){
    let {phone}=req.body

})





module.exports=routerXkx




